package com.example.a12138.myapplication.http;

import android.content.Context;

import com.example.a12138.myapplication.model.Book;
import com.example.a12138.myapplication.model.Realinfo;
import com.example.a12138.myapplication.model.User;
import com.xdw.mvp.http.DataManager;
import com.xdw.mvp.http.ResultFunc;

import java.util.List;

import rx.Observable;

public class MyDataManager extends DataManager {
    private HttpApiInterface httpApiInterface;
    private volatile static MyDataManager instance;
    private MyDataManager(Context context) {
        httpApiInterface=(HttpApiInterface) super.create(context);
    }

    public static MyDataManager getInstance(Context context) {
        if (instance == null) {
            synchronized (MyDataManager.class) {
                if (instance == null) {
                    instance = new MyDataManager(context);
                }
            }
        }
        return instance;
    }

    //下面部分用来编写对apiService中的方法的调用，并且将Result剥离出来
    public Observable<Book> getBookById(int book_id){
        return httpApiInterface.getBookById(book_id).map(new ResultFunc<Book>());
    }


    public Observable<User> login(String username,String password){
        return httpApiInterface.login(username,password).map(new ResultFunc<User>());
    }

    public  Observable<List<Realinfo>> getRealinfoList(int real_info_type_id,int page){
        return httpApiInterface.getRealinfoList(real_info_type_id, page).map(new ResultFunc<List<Realinfo>>());
    }
}
